package com.example.binpacking.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.binpacking.model.FunInterview;
import com.example.binpacking.model.InterviewContent;
import com.example.binpacking.model.Interviewer;
import com.example.binpacking.model.dto.IndividualDto;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Mapper
public interface InterviewerMapper extends BaseMapper<Interviewer> {
    @Select("SELECT parentid,loginid,name,phone,email,orderid FROM tbl_login_interview WHERE loginid = #{loginid} AND password = #{password}")
    List<Interviewer> findByLoginIdAndPassword(@Param("loginid") BigDecimal loginid, @Param("password") String password);

    @Insert("INSERT INTO tbl_login_interview (loginid, password,orderid)\n" +
            "SELECT MAX(orderid) + 1 + 10000000000, MD5(MAX(orderid) +1 + 10000000000),MAX(orderid) +1\n" +
            "FROM tbl_login_interview;")
    int insert();

    @Select("SELECT * FROM tbl_login_interview\n" +
            "ORDER BY orderid DESC\n" +
            "LIMIT 1;")
    Interviewer selectByMaxOrderId();
    @Insert("INSERT INTO tbl_fun_interview (loginid,rightid) VALUES (#{loginid},#{rightid});")
    int insertByLoginidAndRightid(@Param("loginid")String loginid,@Param("rightid")String rightid);
    @Select("select * from tbl_login_interview where loginid=#{loginid} ")
    List<Interviewer> selectByLoginid(@Param("loginid")String loginid);

    @Select("select name from tbl_login_interview where loginid=#{loginid} ")
    String selectNameByLoginid(@Param("loginid")String loginid);

    @Update("UPDATE tbl_login_interview SET  name = #{name}, phone = #{phone}, email = #{email} WHERE loginid = #{loginid}")
    int updateUser(@Param("loginid") String loginid, @Param("name") String name, @Param("phone") String phone, @Param("email") String email);

    @Select("SELECT password, loginid, orderid, phone, name, createdate, isdeleted, email, parentid FROM tbl_login_interview WHERE loginid = #{loginid}")
    List<Map<String, Object>> selectUserDetails(@Param("loginid") String loginid);

    @Update("UPDATE tbl_login_interview SET password = #{newkey} WHERE loginid = #{loginid} AND password = #{originalkey}")
    int updatePassword(@Param("loginid") String loginid, @Param("originalkey") String originalkey, @Param("newkey") String newkey);

}
